package com.thinkgem.jeesite.modules.sys.web;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.*;
import com.thinkgem.jeesite.modules.sys.service.CheckAllService;
import com.thinkgem.jeesite.modules.sys.service.TbOrderProductService;
import com.thinkgem.jeesite.modules.sys.service.TbOrderService;
import com.thinkgem.jeesite.modules.sys.service.TenementPayInfoService;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * Created by jyy on 2016/10/19 0019.
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/CheckAllController")
public class CheckAllController extends BaseController {

    @Autowired
    private CheckAllService checkAllService;
    @Autowired
    private TbOrderService tbOrderService;
    @Autowired
    private TbOrderProductService tbOrderProductService;
    @Autowired
    private TenementPayInfoService tenementPayInfoService;



    // 查询所有订单信息
    @RequestMapping(value = "orderList")
    public String OrderList(TbOrder tbOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<TbOrder> page = checkAllService.findTbOrderByPage(new Page<TbOrder>(request, response), tbOrder);
        if(page.getList().size()==0){
            model.addAttribute("message1","无查询结果");
        }
        model.addAttribute("page", page);
        return "modules/sys/CheckAllOrderList";
    }
    //查询所有物业信息
    @RequestMapping(value = "tenementlist")
    public String listTenement(TbUserTenementInfo tbUserTenementInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<TbUserTenementInfo> page = checkAllService.findUserTenementInfoPage(new Page<TbUserTenementInfo>(request, response), tbUserTenementInfo);
        if(page.getList().size()==0){
            model.addAttribute("message1","无查询结果");
        }
        model.addAttribute("page", page);
        return "modules/sys/CheckAllTenementList";
    }
    // 查看订单明细
    @RequestMapping(value = "queryOrder/{orderId}")
    public String queryOrderProduct(@PathVariable("orderId") Integer orderId, Model model) {
        TbOrder tbOrder = tbOrderService.queryOrder(orderId);
        model.addAttribute("tbOrder", tbOrder);
        List<TbOrderProduct> tbOrderProductList = tbOrderProductService.queryTbOrderProducts(orderId);
        model.addAttribute("tbOrderProductList", tbOrderProductList);
        if(tbOrderProductList.size()==0){
            model.addAttribute("message1","无查询结果");
        }

        return "modules/sys/CheckOneOrderDetail";
    }
    //所有物业缴费记录
    @RequestMapping(value="queryPayInfo")
    public String queryByUid(TbUserTenementInfo tbUserTenementInfo, HttpServletRequest request, HttpServletResponse response,Model model){
       Page<TbUserTenementInfo> page=checkAllService.findPayInfoList(new Page<TbUserTenementInfo>(request, response),tbUserTenementInfo);
        if(page.getList().size()==0){
            model.addAttribute("message1","无查询结果");
        }
       model.addAttribute("page", page);
        List tlist=tenementPayInfoService.getAllListMoney(tbUserTenementInfo);
        model.addAttribute("one",tlist.get(0));
        model.addAttribute("two",tlist.get(1));
        model.addAttribute("three",tlist.get(2));
        model.addAttribute("six",tlist.get(3));
        model.addAttribute("maxMoney",tlist.get(4));
        if(null==tbUserTenementInfo||(null!=tbUserTenementInfo&&null==tbUserTenementInfo.getBeginDate())){
            Date date=new Date();
            tbUserTenementInfo.setBeginDate(date);
            tbUserTenementInfo.setEndDate(date);
        }
        return "modules/sys/CheckAllPayInfoList";
    }


    /**
     * 查询所有商品——分页
     */
    @RequestMapping(value = {"showProductList", ""})
    public String showProductList(TbAgentProduct tbAgentProduct, HttpServletRequest request, HttpServletResponse response, Model model) {
        User user = UserUtils.getUser();
        tbAgentProduct.setAgentId(user.getId());
        Page<TbAgentProduct> page = checkAllService.findProductByPage(new Page<TbAgentProduct>(request, response), tbAgentProduct);
        if(page.getList().size()==0){
            model.addAttribute("message1","无查询结果");
        }
        model.addAttribute("page", page);
        return "modules/sys/allProductList";

    }

}
